package Work;

public class Test {
    public static void main(String[] args) {
        CreatStack stack = new CreatStack();
        stack.push(12);
        stack.push(8);
        stack.push(5);
        stack.push(9);
        System.out.println("弹出栈顶元素" + stack.pop());
        System.out.println("弹出栈顶元素" + stack.pop());
        System.out.println("弹出栈顶元素" + stack.pop());
        System.out.println("弹出栈顶元素" + stack.pop());
        System.out.println("栈顶元素为：" + stack.peek());
        System.out.println("栈是否为空：" + stack.isEmpty());
        System.out.println("栈中元素的个数：" + stack.size());

        piPei("()()())");
    }
    public static void piPei(String str){
        CreatStack creatStack = new CreatStack();
        for (int i = 0; i < str.length(); i++) {
            if (str.charAt(i) == '(') {
                creatStack.push(str.charAt(i));
            } else if(str.charAt(i) == ')') {
                if (creatStack.isEmpty()) {
                    System.out.println(false);
                    System.exit(1); // JVM 直接退出
                }
                Object peek = creatStack.peek();
                if (peek instanceof Character ch) {
                    if (ch == '(') {
                        creatStack.pop();
                    }
                }
            }
        }
        System.out.println(creatStack.isEmpty() ? "true" : "false");
    }
}
